package com.beidouapp.translator;



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanPostProcessor;

import com.beidouapp.translate.Translator;


public class TranslatorScanner implements BeanPostProcessor, BeanFactoryAware{

	    private static final Logger logger =  LoggerFactory.getLogger(TranslatorScanner.class);
	    
	    private BeanFactory m_factory;

	    @Override
	    public Object postProcessAfterInitialization (Object object, String beanName) throws BeansException
	    {
	        if (object instanceof Translator)
	        {
	        	logger.debug("开始初使化[beanName:"+beanName+"]");
	            Translator translator = (Translator) object;
	            TranslatorManager translatorManager = 
	                (TranslatorManager) m_factory
	                    .getBean ("translatorManager");
	            translatorManager.addTranslator (translator);
	        }
	  
	        return object;
	    }

	    @Override
	    public Object postProcessBeforeInitialization (Object object, String beanName) throws BeansException
	    {
	        return object;
	    }

	    @Override
	    public void setBeanFactory (BeanFactory factory) throws BeansException
	    {
	        m_factory = factory;
	    }
	    

}
